from sqlalchemy import Column, Integer, String
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship

from database.models.Controller import Controller
from database.models.DatabaseCommon import Base


class ControllerPoint(Base):
    __tablename__ = 'ControllerPoints'
    id = Column(Integer, primary_key=True, autoincrement=True)
    PointIndex = Column(Integer)
    name = Column(String,default='')
    Value = Column(String,default='')
    ControllerID = Column(Integer, ForeignKey('Controller.id'))
    controller = relationship('Controller', back_populates='points')

    def __repr__(self):
        return "<Points (id='%d', Controller='%d')>" % (
            self.id, self.ControllerID)


Controller.points = relationship('ControllerPoint', order_by=ControllerPoint.id, back_populates='controller')
